package com.mylife.bill.controller;

import com.mylife.bill.vo.AccountInformationVo;
import com.mylife.bill.vo.BillVO;
import com.mylife.bill.vo.DifNecessityCostVO;
import com.mylife.bill.vo.DifTypeCostVO;
import com.mylife.pojo.PageDataInfo;
import com.mylife.pojo.Result;
import com.mylife.bill.service.BillService;
import com.mylife.bill.vo.params.BillParams;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 记账功能
 * @author blueCat
 * @since 2022/2/23
 */
@RestController
@RequestMapping("/mylife/bill")
public class BillController {

    @Autowired
    private BillService billService;

    /**
     * 新增账单
     * @param params
     * @return String
     */
    @PostMapping("/addBill")
    public Result addBill(@RequestBody BillParams params){
        return billService.addBill(params);
    }

    /**
     * 查询账单
     * @param params
     * @return
     */
    @PostMapping("/queryBills")
    public List<BillVO> queryBills(@RequestBody BillParams params){
        Result result = billService.queryBills(params);
        PageDataInfo pageDataInfo =(PageDataInfo)result.getResult();
        long total = pageDataInfo.getTotal();
        List<BillVO> data = (List<BillVO>)pageDataInfo.getData();
        if (data.size() > 0){
            data.get(0).setTotal(total);
        }
        return data;
    }

    /**
     * 查询全部消费类型
     * @return
     */
    @PostMapping("/queryConsumptionType")
    public List<String> queryConsumptionType(){
        return billService.queryConsumptionType();
    }

    /**
     * 根据消费类型查询全部消费内容
     * @return
     */
    @PostMapping("/queryConsumptionContent")
    public List<String> queryConsumptionContent(@RequestBody BillParams params){
        return billService.queryConsumptionContent(params.getConsumptionType());
    }

    /**
     * 查询消费总额
     * @param params
     * @return
     */
    @PostMapping("/queryConsumptionAmount")
    public String queryConsumptionAmount(@RequestBody BillParams params){
        return billService.queryConsumptionAmount(params);
    }

    /**
     * 新增记账类型
     * @param params
     * @return
     */
    @PostMapping("addBillType")
    public Result addBillType(@RequestBody BillParams params){
        return billService.addBillType(params);
    }

    /**
     * 删除帐单
     * @param params
     * @return
     */
    @PostMapping("/deleteBill")
    public Result deleteBill(@RequestBody BillParams params){
        return billService.deleteBill(params.getId());
    }

    /**
     * 查询单条账单
     * @param params
     * @return
     */
    @PostMapping("/queryOneBill")
    public BillVO queryOneBill(@RequestBody BillParams params){
        return billService.queryOneBill(params.getId());
    }

    /**
     * 修改单条账单
     * @param params
     * @return
     */
    @PostMapping("/updateBill")
    public Result updateBill(@RequestBody BillParams params){
        return billService.updateBill(params);
    }

    /**
     * 查询不同重要性消费
     * @param params
     * @return
     */
    @PostMapping("/queryDifNecessityCost")
    public List<DifNecessityCostVO> queryDifNecessityCost(@RequestBody BillParams params){
        return billService.queryDifNecessityCost(params);
    }

    /**
     * 查询不同消费类型消费
     * @param params
     * @return
     */
    @PostMapping("/queryDifTypeCost")
    public List<DifTypeCostVO> queryDifTypeCost(@RequestBody BillParams params){
        return billService.queryDifTypeCost(params);
    }

    /**
     * 查询全部账户类型
     * @return
     */
    @PostMapping("/queryAccountType")
    public List<String> queryAccountType(){
        return billService.queryAccountType();
    }

    /**
     * 改变账户信息
     * @param params
     * @return
     */
    @PostMapping("/changeAccountInformation")
    public Result changeAccountInformation(@RequestBody BillParams params){
        return billService.changeAccountInformation(params);
    }

    /**
     * 查询全部账户信息
     * @param params
     * @return
     */
    @PostMapping("/queryAccountInformation")
    public List<AccountInformationVo> queryAccountInformation(@RequestBody BillParams params){
        return billService.queryAccountInformation(params.getUsername());
    }


    /**
     * 删除账号信息
     * @param params
     * @return
     */
    @PostMapping("/deleteAccount")
    public Result deleteAccount(@RequestBody BillParams params){
        return billService.deleteAccount(params.getId());
    }
}
